<?php

namespace frontend\modules\yii2\models;

use Yii;
use yii\base\Model;

/**
 * Login form
 */
class Device extends Model
{
    public $id;         // 设备id
    public $name;       // 设备名称
    public $brightness; // 灯光亮度
    public $isOnOff;    // 状态：开或者关
    public $color;      // 灯光颜色
    public $url;
    public $active;
    public $age;
    public $age_repeat;
    public $school_age;
    public $created_at;
    public $money;
    public $email;
    public $ages;
    public $gendor;
    public $ips;
    public $tel;

    public function rules()
    {
        return [
            // id, name, isOnOff 是light设备和switch设备都必须要有的属性
            [["id", "name", "isOnOff","brightness","color"], "required"],
            // brightness亮度只能是light的属性，取值范围是从 0 到 100
            ["brightness", "in", "range" => range(0, 100)],
            // color灯色也只能是light的属性，取值范围只能是红、黄、蓝
            ["color", "in", "range" => ["red", "yellow", "blue"]],

        ];
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();

        // 定义灯设备场景下的属性列表
        $scenarios["light"] = ["id", "name", "isOnOff", "color", "brightness"];
        // 定义开关面板设备的属性列表
        $scenarios["switch"] = ["id", "name","isOnOff"];

        return $scenarios;
    }
}